<?php
	include_once("../persistent/BaseObject.php");
	
	class User extends BaseObject{
		public $Username;
		public $Password;
		public $Nickname;
		
		public function __construct($d){
			$this->tableName = "Users";
			parent::__construct($d);	
		}	
		
		public function findNUsers($N){
			$con = $this->openDB();
			
			// 找出Username的条目
			$sql = "SELECT * FROM $this->tableName
			LIMIT $N";
			
			return $this->startSQL($sql,$con);
		}
		
		public function findNUsernames($N){
			$usernames = array();
			$userlist = $this->findNUsers($N);
			
			while ($user = mysql_fetch_array($userlist))
				$usernames[] = $user['Username'];
			
			return $usernames;
		}
		
		public function findValueByUsername($username){
			$con = $this->openDB();
			
			// 找出Username的条目
			$sql = "SELECT * FROM $this->tableName
			WHERE Username = '$username'";
			
			return mysql_fetch_array($this->startSQL($sql,$con));
		}
		
		public function getGroupnamelistByUsername($username)
		{
			$con = $this->openDB();
			$anotherTable = "Memberof";
			
			$sql = "SELECT * FROM $anotherTable
			WHERE Username = '$username'";
			
			$list = $this->startSQL($sql,$con);
			$group_names = array();
			while($row = mysql_fetch_array($list))
				$group_names[] = $row['Groupname'];
				
			return $group_names;
		}
	}

?>
